home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 May / PCPlus May 1998=disk A.iso / full / CBUILDER / SAMS / SAMPLES / CHAP02 / SCOPE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-12  |  715 b   |  38 lines

  1. #include <iostream.h>
  2. #include <conio.h>
  3. #pragma hdrstop
  4.  
  5. int x = 20;
  6. void TestFunction(int);
  7.  
  8. int main(int, char**)
  9. {
  10.   int x = 40;
  11.   int i = 0;
  12.   cout << endl << "Global x = " << ::x << endl;
  13.   cout << "In main program x = " << x << endl;
  14.   bool done = false;
  15.   while (!done) {
  16.     int x;
  17.     x = -1;
  18.     cout << endl << "Enter a number (-1 to exit): ";
  19.     cin >> x;
  20.     if (x != -1) {
  21.       cout << endl << "In while loop x = " << x;
  22.       TestFunction(++i);
  23.     }
  24.     else 
  25.       done = true;
  26.   }
  27.   cout << endl << "Press any key to continue...";
  28.   getch();
  29.   return 0;
  30. }
  31.  
  32. void TestFunction(int x)
  33. {
  34.   cout << ", While loop has executed "
  35.     << x << " times." << endl;
  36. }
  37.  
  38.